const Model = require('./Model')

class User extends Model {
  // 登录
  static doLogin(username, password) {
    return new Promise((resolve, reject) => {
      const sql = 'SELECT id, username FROM `user` WHERE username=? AND `password`=?'
      this.query(sql, [username, password])
        .then(resolve)
        .catch(reject)
    })
  }
  // 最后登录时间
  static lastLoginTime() {
    return new Promise((resolve, reject) => {
      const sql = "SELECT `time` FROM log WHERE handle='登录' ORDER BY `time` DESC LIMIT 1"
      this.query(sql)
        .then(resolve)
        .catch(reject)
    })
  }
}

module.exports = User